package com.jws.battleship;

import java.util.ArrayList;
import java.util.Date;

public class Game 
{
	private ArrayList<Coordinate> mShots;
	private ArrayList<Ship> mMyShips;
	private ArrayList<Ship> mOpponentsShips;
	private ArrayList<Friend> mOpponents;
	private String mTurn;
	private Date mCreatedDate;
	
	public Game()
	{
		mShots = new ArrayList<Coordinate>();
		mMyShips = new ArrayList<Ship>();
		mOpponents = new ArrayList<Friend>();
		mOpponentsShips = new ArrayList<Ship>();
		mTurn = "";
		mCreatedDate = new Date();
	}
	
	public ArrayList<Coordinate> getShots() {
		return mShots;
	}

	public void setShots(ArrayList<Coordinate> shots) {
		this.mShots = shots;
	}

	public ArrayList<Ship> getMyShips() {
		return mMyShips;
	}

	public void setMyShips(ArrayList<Ship> myShips) {
		this.mMyShips = myShips;
	}

	public ArrayList<Ship> getOpponentsShips() {
		return mOpponentsShips;
	}

	public void setOpponentsShips(ArrayList<Ship> opponentsShips) {
		this.mOpponentsShips = opponentsShips;
	}

	public ArrayList<Friend> getOpponents() {
		return mOpponents;
	}
	
	public String getOpponentsIDs()
	{
		StringBuilder sb = new StringBuilder();
		
		for (Friend friend : mOpponents) {
			sb.append(friend.getUniqueID());
			sb.append(";");
		}
		
		sb.deleteCharAt(sb.length()-1);
		
		return sb.toString();
	}

	public void setOpponents(ArrayList<Friend> opponents) {
		this.mOpponents = opponents;
	}

	public String getTurn() {
		return mTurn;
	}

	public void setTurn(String turn) {
		this.mTurn = turn;
	}

	public Date getCreatedDate() {
		return mCreatedDate;
	}
	
	public String getPersistableDate()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(mCreatedDate.getDate());
		sb.append("-");
		sb.append(mCreatedDate.getMonth());
		sb.append("-");
		sb.append(mCreatedDate.getYear());
		
		return sb.toString();
	}
	
	public void setCreatedDate(Date date) {
		mCreatedDate = date;
	}
	
	public void setCreatedDate(String date) {
		String[] value = date.split("-");
		
		mCreatedDate.setDate(Integer.parseInt(value[0]));
		mCreatedDate.setMonth(Integer.parseInt(value[1]));
		mCreatedDate.setYear(Integer.parseInt(value[2]));
	}

	public void addOpponent(Friend opponent)
	{
		mOpponents.add(opponent);
	}
}
